module nade.window;

import derelict.opengl.gl;

import nade.hud;
import nade.vector;
import nade.region;
import nade.color;
import nade.primitive;
import nade.font;
import nade.clipper;


class Window : HUD, IFrame {
	override void render(const Region2 area)
	{
		renderWindow(area);

		glPushMatrix();
		glTranslatef(area.min.x, area.min.y, 0);
		super.render();
		glPopMatrix();
	}

	void renderWindow(const Region2 area)
	{
		Color.BLACK.render(0.5);
		renderFilledRectangle(area.min.as!(Vector2), area.max.as!(Vector2));

		Color.WHITE.render;
		renderRectangle(area.min.as!(Vector2), area.max.as!(Vector2));
	}

	override bool click(Vector2 position)
	{
		super.click(position);
		return true;
	}

	override Vector2i sizeMin() { return Vector2i(16, 16); }
	override Vector2i sizeMax() { return Vector2i(int.max, int.max); }
}


class LabelledWindow : Window {
	this(string title)
	{
		_title = title;
	}

	override void renderWindow(const Region2 area)
	{
		super.renderWindow(area);

		font.printCenter(area.min.x + area.width*0.5, area.max.y - 16, _title, 16);
	}

	string title() { return _title; }
	string title(string rhs) { return _title = rhs; }

	private {
		string			_title;
	}
}
